<?php


if (isset($listSports)){
    
    if (!empty($listSports)) {
    ?>
    <h2> Choose a sport to update </h2>
    <table>
        <thead>
            <tr>
                <td>Sport Id</td>
                <td>Sport Name</td>
                <td>Option</td>
            </tr>
        </thead>
        <tbody>
        <?php 
        foreach ($listSports as $k => $s){
        ?>
            <tr>
                <td> <?php echo $k;?> </td>  
                <td> <?php echo $this->Html->link($s, array('action' => 'admin_update', $k));?> </td>  
                <td> <?php echo $this->Html->link('Delete', array('action' => 'admin_del_sport', $k));?> </td>  
            </tr>
        <?php        
        }
        ?>
        </tbody>
    </table>
    <?php
    }
    else{
        ?>
        <p> Aucun sport n'est enregistré dans la base de donnée ! </p>
        <p> Ajoutez en un maintenant ! </p>
        
    <?php
    }
    ?>
        
    <div class="clear">
        <h3 >Add a sport</h3>
        <?php
        echo $this->Form->create('Sport');
        echo $this->Form->input('name', array(
            'label' => 'Sport name'
        ));
        echo $this->Form->end('Add');
        ?>

    </div>
        <?php
   
}
else{
    $tricksTypes = $sport['TricksType'];

    $listTricksTypes = array();
    foreach ($tricksTypes as $t){
        $listTricksTypes[$t['id']] = $t['name'];
    }

    //debug($sport);
    $tricks = $sport['Trick'];
    $sport = current($sport);



    ?>

    <h2> <?php echo $sport['name'];?></h2>


    <div class="col5 left">   
        <div>
            <h3> Add a new trick type </h2>
            <?php

            echo $this->Form->create('TricksType');
            echo $this->Form->input("TricksType.name");
            echo $this->Form->input("TricksType.description", array(
                'type' => 'textarea'
            ));
            echo $this->Form->end("Add");


            if (!empty($tricksTypes)){
            ?>
            <table>
                <thead>
                    <tr>
                        <td>Name</td>
                        <td colspan="4">Options</td>
                    </tr>
                </thead>
                <tbody>
                <?php
                foreach ($tricksTypes as $tricksType){
                ?>
                <tr>
                    <td><?php echo $tricksType['name'];?></td>
                    <td><?php echo $this->Html->link('Update', array('action' => 'update'));?> </td>
                    <td><?php echo $this->Html->link('Delete', array('action' => 'update'));?></td>
                    <td><?php echo $this->Html->link('Show More', array('action' => 'showMore'));?></td>
                </tr>
                <?php
                }
                ?>
                </tbody>
            </table>
                <?php
            }
            ?>
        </div>
        <div>
            <h3>Modifier les informations : </h3>

            <?php
            echo $this->Form->create("Sport");        
            
            echo $this->Form->input("Sport.name", array(
                'value' => $sport['name']
            ));
            echo $this->Form->input("Sport.description", array(
                'value' => $sport['description']
            ));
            echo $this->Form->end("Save");
            ?>
        </div>

    </div>
    <div class="col5 right">
        <div>
        <h3> Add a trick </h3>
        <?php


        echo $this->Form->create('Trick');
        ?>
        <fieldset>
        <?php
        echo $this->Form->input("Trick.name");
        echo $this->Form->input("Trick.tricks_types_id", array(
            'options' => $listTricksTypes
        ));
        echo $this->Form->input("Trick.description");
        ?>
        </fieldset>     
        <?php
        echo $this->Form->end("Add");
        ?>

       <?php

        if (!empty($tricks)){
            ?>
            <table>
                <thead>
                    <tr>
                        <td>Name</td>
                        <td>Trick Type</td>
                        <td colspan="4">Options</td>
                    </tr>
                </thead>
                <tbody>
            <?php
            foreach ($tricks as $trick){           
            ?>
                <tr>
                    <td><?php  echo $trick['name'];?> </td>
                    <td><?php  echo $listTricksTypes[$trick['tricks_types_id']];?> </td>
                    <td><?php echo $this->Html->link('Update', array('action' => 'update'));?> </td>
                    <td><?php echo $this->Html->link('Delete', array('action' => 'update'));?></td>
                    <td><?php echo $this->Html->link('Show More', array('action' => 'showMore'));?></td>
                </tr>
            <?php
            }
            ?>
            </table>
            <?php
        }

        ?>
        </div>


        <div>

            <h3> Add a new Spot </h3>

            <?php
            echo $this->Form->create();
            echo $this->Form->input("Spot.name");
            echo $this->Form->end("Add");


            if (!empty($spots)){
                foreach ($spots as $d){           
                ?>
                    <li> <?php  echo $d['name'];?> </li>
                <?php
                }
            }

            ?>
        </div>
    </div>
    
    <?php
}
?>

    